package com.xy.biz.xd.domain.converter;

import com.xy.biz.xd.domain.bo.TechniqueBO;
import com.xy.biz.xd.domain.po.TechniquePO;
import com.xy.biz.xd.domain.query.TechniqueByIdQuery;
import com.xy.biz.xd.domain.query.TechniqueQuery;
import com.xy.biz.xd.domain.req.GetTechniqueRequest;
import com.xy.biz.xd.domain.req.ListTechniqueRequest;
import com.xy.biz.xd.domain.req.SaveTechniqueRequest;
import com.xy.biz.xd.domain.resp.GetTechniqueResponse;
import com.xy.tool.util.BeanUtilsEx;

import java.util.Collection;
import java.util.List;

/**
 *
 *
 * @author zgy
 * @date 2022-1-11
 */
public class TechniqueConverter {

    public static TechniquePO toPO(TechniqueBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new TechniquePO(), true);
    }

    public static List<TechniquePO> toPO(Collection<TechniqueBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new TechniquePO(), true);
    }

    public static TechniqueBO fromPO(TechniquePO source) {
        return BeanUtilsEx.copyProperties(source, () -> new TechniqueBO());
    }

    public static List<TechniqueBO> fromPO(Collection<TechniquePO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new TechniqueBO());
    }

    public static TechniqueBO toBO(SaveTechniqueRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new TechniqueBO(), (s, t) -> {
            t.setTechniqueDocumentList(TechniqueDocumentConverter.toBO(s.getTechniqueDocumentList()));
        });
    }

    public static List<TechniqueBO> toBO(Collection<SaveTechniqueRequest> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new TechniqueBO(), true);
    }

    public static GetTechniqueResponse toResponse(TechniqueBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GetTechniqueResponse());
    }

    public static List<GetTechniqueResponse> toResponse(Collection<TechniqueBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, GetTechniqueResponse::new, (s, t) -> {
            t.setTechniqueDocumentList(TechniqueDocumentConverter.toResponse(s.getTechniqueDocumentList()));
        });
    }

    public static TechniqueQuery toQuery(ListTechniqueRequest source) {
        if (null == source) {
            return null;
        }
        TechniqueQuery target = new TechniqueQuery(source.getPageIndex(), source.getPageSize());
        BeanUtilsEx.copyProperties(source, target);
        return target;
    }

    public static TechniqueByIdQuery toQuery(GetTechniqueRequest source) {
        return BeanUtilsEx.copyProperties(source, TechniqueByIdQuery::new);
    }

}
